const mysql=require('mysql')
let pool=mysql.createPool({
    host:'127.0.0.1',
    user:'root',
    password:'root',
    database:'scnku'
})

const exec=(sql,params=[])=>{
    return new Promise((resolve,reject)=>{
        pool.getConnection((err,conn)=>{
            if(err){
                console.log(err.message);
                reject('连接数据库失败!')
            }
            conn.query(sql,params,(err,result)=>{
                if(err){
                    console.log(err.message);
                    reject('执行sql语句失败!')
                }
                resolve(result)
            })
        })  
    })
}
module.exports={
    exec
}